package main

import (
	"fmt"
	"strconv"
	"time"
)

func main()  {
	intChan := make(chan int,10)
	for i:=0;i<10;i++ {
		intChan <- i
	}

	stringChan := make(chan string,10)
	for i:=0;i<10;i++ {
		stringChan <- "hello,"+strconv.Itoa(i)
	}

	for {
		select {
			//如果intChan一直没有关闭，不会一直阻塞而deadlock，会自动调到下一个case匹配
			case v := <-intChan :
				fmt.Printf("从intChan读取的数字%d\n",v)
				time.Sleep(time.Second)
			case v := <-stringChan :
				fmt.Printf("从stringChan去除数据%s\n",v)
				time.Sleep(time.Second)
			default :
				fmt.Println("数据取完了，跳出循环")
				return
		}
	}
}
